/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package jse;

/**
 *
 * @author WangShuai
 */
public class StringReplaceTest {
    public static void main(String[] args) {
        String s = "abcde (1234)@!?-_王";
        //字符替换：Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. 
        System.out.println(s.replace("^\\w", ""));
        //正则表达式替换：Replaces each substring of this string that matches the given regular expression with the given replacement. 
        //删除所有非【数字、字符和下划线】的字符
        System.out.println(s.replaceAll("[^\\w]", ""));
        //删除所有非【汉字、数字、字符和下划线】的字符
        System.out.println(s.replaceAll("[^\\w\\u4e00-\\u9fa5]", ""));
        
        System.out.println("Hello,%NAME%,%ADDRESS%".replace("%NAME%", "swang").replace("%ADDRESS%", "BeiJing"));
    }
}
